
$(document).ready(function () {

    var productName;
    requestData();

    function requestData(){
        $.ajax({
            type:"POST",
            url:'http://59.110.114.107:8888/bank/getFinacialProduct',
            data: {
                pageNum : sessionStorage.getItem("pageNum"),
                pageSize : 10, //页容量，默认为10
                bankName : sessionStorage.getItem("detailBankName"),
                productName : sessionStorage.getItem("detailProductName"),
            },
            success:function (data) {
                if (data.data == null) {
                    alert(data.meta.message);

                }else{
                    if(data.data.Total!=null){


                        sessionStorage.removeItem("pageNum");
                        sessionStorage.removeItem("detailBankName");
                        sessionStorage.removeItem("detailProductName");

                        var detail=data.data["governmentPolicies List"][0];
                        productName=detail.productName;
                        //console.log(detail);

                        $(".detail-bank").html("<dt> <img class='detail-bank_img' src='images/"+detail.bankName+".png'></dt><dd> <h2>"+detail.bankName+"-"+detail.productName+"</h2><p>发布机构："+detail.bankName+"  </p></dd>");
                        $(".table-detal em:eq(0)").html(detail.rateLowerLimit+"%-"+detail.rateUpperLimit+"%");

                        var internetLoanType=detail.internetLoanType==0?"否":"是";
                        $(".table-detal em:eq(1)").html(internetLoanType);
                        var productProperties=detail.productProperties==0?"否":"是";
                        $(".table-detal em:eq(2)").html(productProperties);
                        var generality=detail.generality==0?"否":"是";
                        $(".table-detal em:eq(3)").html(generality);
                        var paymentType=detail.paymentType==0?"否":"是";
                        $(".table-detal em:eq(4)").html(paymentType);

                        var loanType=detail.loanType;
                        if (loanType == "0") {loanType="经营贷款";}
                        if (loanType == "1") {loanType="流动资金贷款";}
                        if (loanType == "2") {loanType="周转贷款";}
                        $(".table-detal em:eq(5)").html(loanType);

                        var proloanLimit = detail.loanLimit;
                        if (proloanLimit == "0") {proloanLimit="100万及以下";}
                        if (proloanLimit == "1") {proloanLimit="200万及以下";}
                        if (proloanLimit == "2") {proloanLimit="300万及以下";}
                        if (proloanLimit == "3") {proloanLimit="500万及以下";}
                        if (proloanLimit == "4") {proloanLimit="1000万及以下";}
                        if (proloanLimit == "5") {proloanLimit="1000万以上";}
                        $(".table-detal em:eq(6)").html(proloanLimit);

                        var loanPeriod = detail.loanPeriod;
                        $(".table-detal em:eq(7)").html(loanPeriod+"月");

                        var proguaranteeMode = detail.guaranteeMode;
                        if (proguaranteeMode == "0") { proguaranteeMode = "抵押";}
                        if (proguaranteeMode == "1") { proguaranteeMode = "信保基金";}
                        if (proguaranteeMode == "2") { proguaranteeMode = "一般保证";}
                        if (proguaranteeMode == "3") { proguaranteeMode = "信用";}
                        if (proguaranteeMode == "4") { proguaranteeMode = "实际控制人夫妇提供个人连带担保";}
                        $(".table-detal em:eq(8)").html(proguaranteeMode);

                        $(".table-detal em:eq(9)").html(detail.useArea);
                        $(".table-detal em:eq(10)").html(detail.description);



                    }
                }

            },
            error: function(XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest.status);
                alert(XMLHttpRequest.readyState);
                alert(textStatus);
            }
        })

    }


    //金融产品详情立即申请
    $("#apply").click(function(){
        var comUsername=window.localStorage.getItem("comUsername");
        if(comUsername==null){
            alert("请登录后在控制台申请");
        }else{
            $.ajax({
                type:"POST",
                url:'http://59.110.114.107:8888/enterprise/productRequest/'+productName,
                data: {
                    socialCode:comUsername,
                    productName:productName,
                    fundUsage:$("#fundUsage").val()
                },
                success: function (data) {
                    alert(data.meta.message);
                    window.location.href="company.html";
                },
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                    alert(XMLHttpRequest.status);
                    alert(XMLHttpRequest.readyState);
                    alert(textStatus);
                }
            });
        }

    });

    //金融产品详情返回
    $("#return").click(function(){
        var comUsername=window.localStorage.getItem("comUsername");
        if(comUsername==null){
            window.location.href="products.html"
        }else {
            window.location.href="company.html"
        }
    });
})
